package org.dromara.admin.enums;

import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * 账单状态: PENDING_PAY(待支付), PAID(已支付), OVERDUE(已逾期)
 */
@Getter
@AllArgsConstructor
public enum BillStatus {

    /**
     * Order->租金/垫资账单状态
     */
    PENDING_PAY("PENDING_PAY", "待支付"),
    PAID("PAID", "已支付"),
    OVERDUE("OVERDUE", "已逾期"),

    /**
     * 账单状态: UNPAID(未付款), PART(部分付款), BILL_PAID(已付款), BAD(坏账)
     */
    UNPAID("UNPAID", "未付款"),
    PART("PART", "部分付款"),
    BILL_PAID("BILL_PAID", "已付款"),
    PAY_FAIL("PAY_FAIL", "支付失败"),
    BAD("BAD", "坏账");

    private final String code;
    private final String info;

    /**
     * 根据code代码获取枚举类型
     *
     * @param code 代码（如："PENDING"）
     * @return 对应的枚举类型
     * @throws IllegalArgumentException 如果找不到匹配的枚举类型
     */
    public static BillStatus getByCode(String code) {
        for (BillStatus type : values()) {
            if (type.getCode().equalsIgnoreCase(code)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型代码: " + code);
    }

    /**
     * 根据info信息获取枚举类型
     *
     * @param info 类型信息（如："审核中"）
     * @return 对应的枚举类型
     * @throws IllegalArgumentException 如果找不到匹配的枚举类型
     */
    public static BillStatus getByInfo(String info) {
        for (BillStatus type : values()) {
            if (type.getInfo().equals(info)) {
                return type;
            }
        }
        throw new IllegalArgumentException("无效的类型: " + info);
    }
}
